package com.atguigu.lease.web.admin.tasks;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyTask {

    @Autowired
    private LeaseAgreementService leaseAgreementService;
    @Scheduled(cron = "0/10 * * * * *")
    public void checkLeaseStatus(){
        //修改租约表的状态 在租状态  2 5 7
        //last_end_date < 当前时间 -》时间过期
        //修改 状态 已到期
        LambdaUpdateWrapper<LeaseAgreement> lambdaUpdateWrapper
                = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper
                .in(LeaseAgreement::getStatus, LeaseStatus.SIGNED, LeaseStatus.WITHDRAWING, LeaseStatus.RENEWING);
        lambdaUpdateWrapper.lt(LeaseAgreement::getLeaseEndDate,new Date());
        lambdaUpdateWrapper.set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED);
        leaseAgreementService.update(lambdaUpdateWrapper);



    }
}
